package com.zzg.datastructure.stack;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;

/**
 * @Author zhengzg
 * @Date 2022-08-18
 * @Version v1.0
 */
@Getter
@AllArgsConstructor
public enum Operation {

    ADD("+",1),
    SUB("-",1),
    MUL("*",2),
    DEL("/",2);

    /**
     * 符号
     */
    private String symbol;

    /**
     * 等级
     */
    private int rank;

    /**
     * 根据符号获取优先级
     * @param symbol 符号
     * @return 优先级
     */
    public static int getRank(String symbol){
        Operation[] values = Operation.values();
        for (Operation o : values){
            if (Objects.equals(o.getSymbol(),symbol)){
                return o.getRank();
            }
        }
        return -1;
    }
}
